#ifndef VTreeModel_H
#define VTreeModel_H

#include "VSqlDatabase.h"
#include "VTreeNode.h"
#include "VTreeSql.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

class VTreeModel : public QAbstractItemModel
{
	Q_OBJECT

public:
	VTreeModel(QObject *parent = 0);
	~VTreeModel();

	void setRootNode(VTreeNode *node);
	VTreeNode *rootNode() const { return m_rootNode;}
	QModelIndex rootIndex() const { return createIndex(0,0,m_rootNode);}
	
	QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
	QModelIndex parent(const QModelIndex &index) const;

	virtual bool hasChildren (const QModelIndex &parent = QModelIndex()) const;
	virtual bool canFetchMore(const QModelIndex &parent) const;
	virtual void fetchMore   (const QModelIndex &parent);

	QVariant headerData(int section, Qt::Orientation orientation,int role = Qt::DisplayRole) const;

	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent = QModelIndex()) const;
	
	Qt::ItemFlags flags(const QModelIndex &index) const;
	Qt::DropActions supportedDropActions() const;
	QStringList mimeTypes() const;
	QMimeData *mimeData(const QModelIndexList &indexes) const;
	bool dropMimeData(const QMimeData *data,Qt::DropAction action, int row, int column, const QModelIndex &parentIndex);
	
	QVariant data(const QModelIndex &index, int role) const;
	bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

	bool insertRows(int position, int rows,	const QModelIndex &parentIndex = QModelIndex());
	bool removeRows(int position, int rows,	const QModelIndex &parentIndex = QModelIndex());
	
	QModelIndex indexFromNode(VTreeNode *node) const;
	VTreeNode *nodeFromIndex(const QModelIndex &index) const;

private:
	VTreeNode *m_rootNode;
};

///////////////////////////////////////////////////////////////////////////////

#endif
